
const schedule = require('node-schedule');

var updateResults = require('./utils/WinningResults')// get请求模块

const { DATABASE_NAME, DATABASE_USERNAME, HISTORY_PAGE_SIZE, TABLE_CREATE_SUCCESS, DATABASE_HOST, TABLE_HISTORY_NAME, APP_KEY } = require('./constants/constants')
// const myEmitter = require('./utils/emitterUtil');
const { saveData, getData } = require('./utils/cache')
// 连接数据库
require('./db/initDatabase')
function initProject() {
    console.log(`开始初始化项目 请求历史彩票开奖结果`)
    saveData(TABLE_CREATE_SUCCESS, false)

    // 定义规则
    let rule = new schedule.RecurrenceRule();
    rule.hour = 22;
    rule.minute = 0;
    rule.second = 0;
    // 启动定时任务
    let job = schedule.scheduleJob(rule, async () => {
        console.log('定时任务开启成功');
        let isTableCreate =  getData(TABLE_CREATE_SUCCESS)
        if (isTableCreate == false) {
            console.log(`数据表暂未创建`)
        } else {
            await updateResults()
        }

    })

    // myEmitter.on(TABLE_CREATE_SUCCESS, async () => {

    // })


}
module.exports = initProject